package com.tanhua.app.controller;

import com.tanhua.app.service.VideoService;
import com.tanhua.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.websocket.server.PathParam;
import java.io.IOException;

@RestController
public class VideoController {
    @Autowired
    private VideoService videoService;

    @GetMapping(value = "/smallVideos", name = "小视频列表")
    public ResponseEntity smallVideos(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")Integer pagesize) {
        if(page==0){
            page=1;
        }
        PageBeanVo pageBeanVo = videoService.findVideoVoByPage(page, pagesize);
        return ResponseEntity.ok(pageBeanVo);

    }
    @PostMapping(value = "/smallVideos",name="小视频的发布")
    public ResponseEntity saveVideo(MultipartFile videoThumbnail,MultipartFile videoFile) throws IOException {

        return videoService.saveVideo(videoThumbnail,videoFile);
    }

    @PostMapping(value = "/smallVideos/{uid}/userFocus",name="关注小视频作者")
    public ResponseEntity focus(@PathVariable("uid") Long followUserId ) {

        return videoService.focus(followUserId);
    }
    @PostMapping(value = "/smallVideos/{uid}/userUnFocus",name="取消关注小视频作者")
    public ResponseEntity unFocus(@PathVariable("uid") Long followUserId ) {

        return videoService.unFocus(followUserId);
    }

}
